#directory should point to the Analysis folder
directory<-Sys.getenv("US_Ineq_Repl")
CEPR<-file.path(directory, "Data/CEPR")
ORG<-file.path(CEPR, "CPS_ORG/CEPR")
BASIC<-file.path(CEPR, "CPS_Basic/CEPR")
NBER_O<-file.path(CEPR, "CPS_ORG/NBER")
NBER_B<-file.path(CEPR, "CPS_Basic/NBER")


getOption('timeout')
options(timeout=1200)

Y<-sprintf("%02d", 79:93)
r<-0
for (yy in Y) {
  f<-paste0(NBER_O,'/morg',yy,'.dta')
  if(!file.exists(f)){
    u<-paste0('https://data.nber.org/morg/annual/morg',yy,'.dta')
    r<-download.file(u, f, mode = "wb")
  }
  if(r!=0){
    cat(paste0('problem in year ',yy,'\n'))
  }
}